package com.wsp.service.service;

import com.wsp.apimanagement.pojo.dto.Result;
import com.wsp.apimanagement.pojo.entity.Module;
import com.wsp.apimanagement.pojo.vo.ModuleRecord;
import com.wsp.apimanagement.pojo.vo.UserModule;
import com.wsp.apimanagement.service.ModuleService;
import com.wsp.apimanagement.util.CommonResultBuilderUtil;
import com.wsp.service.mapper.ModuleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Package: com.wsp.service.service
 * Description： TODO
 *
 * @Author: 巫思平
 * Copyright: Copyright (c) 2020
 * Version: 1
 */
@Service
public class ModuleServiceImpl implements ModuleService {
    @Autowired
    ModuleMapper moduleMapper;
    @Override
    public Module findModuleByName(String moduleName) {
        return moduleMapper.findModuleByName(moduleName);
    }

    @Override
    public Result<List<Module>> getAllModule() {
        List<Module> res = moduleMapper.getAllModule();
        if(res==null) {
            return CommonResultBuilderUtil.commonError("网络异常");
        }
        return Result.<List<Module>>builder().code(200).msg("SUCCESS").data(res).build();
    }

    @Override
    public Result<List<UserModule>> getUserModule(long userId) {
        List<UserModule> list = moduleMapper.getUserModuleBuUserId(userId);
        return Result.<List<UserModule>>builder().code(200).msg("SUCCESS").data(list).build();
    }

    @Override
    public Result<ModuleRecord> getModuleRecord(long moduleId, int currentPage) {
        return Result.<ModuleRecord>builder().code(200).msg("SUCCESS").data(moduleMapper.getModuleRecord(moduleId, currentPage)).build();
    }
}
